package com.stgl.service;

import com.stgl.dao.BmqkDao;
import com.stgl.dao.SthdfdbDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SthdfdbService {
    @Autowired
    private SthdfdbDao sthdfdbDao;

    @Autowired
    private BmqkDao bmqkDao;

    public List<Map<String,Object>>Search_sthdfdb(Map<String,Object>gmap)
    {
        List<Map<String,Object>>list1=sthdfdbDao.Search_sthdfdb(gmap);
        for(int i=0;i<list1.size();i++){
            Map<String,Object>maps=list1.get(i);
            List<Map<String,Object>>list2=sthdfdbDao.Search_Stksf(maps);
            List<Map<String,Object>>list3=sthdfdbDao.Search_Stk_teacher(maps);
            maps.put("stksf",list2);
            maps.put("stkteacher",list3);
        }
        return list1;
    }


    public Map<String,Object> del_stkfdb(Map<String,Object>gmap)
    {
        Map<String,Object>rmap=new HashMap<String,Object>();
        //先查询该辅导班是否已经有学生报名 如果有 则不能删除
        List<Map<String,Object>>list1=new ArrayList<>();
        list1=bmqkDao.Search_sthdbmqkNow(gmap);
        if(list1.size()>0){
            rmap.put("msg","该辅导班已经有学生报名,不能删除,请联系开发人员!");
            rmap.put("result",false);
        }else{
            sthdfdbDao.del_stkfdb(gmap);
            sthdfdbDao.del_Stksf(gmap);
            sthdfdbDao.del_Stk_teacher(gmap);
            rmap.put("msg","删除成功!");
            rmap.put("result",true);
        }
        return rmap;
    }



    public int InsertStkfdb(Map<String,Object>gmap)
    {
        return sthdfdbDao.InsertStkfdb(gmap);
    }

    public int InsertStksf(Map<String,Object>gmap)
    {
        return sthdfdbDao.InsertStksf(gmap);
    }


    public int InsertStk_teacher(Map<String,Object>gmap)
    {
        return sthdfdbDao.InsertStk_teacher(gmap);
    }


    public int EditStkfdb(Map<String,Object>gmap)
    {
        int i=sthdfdbDao.EditStkfdb(gmap);
        sthdfdbDao.del_Stksf(gmap);
        sthdfdbDao.del_Stk_teacher(gmap);
        return i;
    }

    public void delHistoryStkfdb(Map<String,Object>gmap)
    {
        sthdfdbDao.delHistoryStkfdb(gmap);
    }

    public void resHistoryStkfdb(Map<String,Object>gmap)
    {
        sthdfdbDao.resHistoryStkfdb(gmap);
    }

}
